maplistmodel: Make constructor transfer full
authorMatthias Clasen <mclasen@redhat.com>
Sun, 26 Jul 2020 18:20:25 +0000 (14:20 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sun, 26 Jul 2020 22:02:51 +0000 (18:02 -0400)
This is for consistency with other wrapping list constructors.
We want them all to be transfer full, allow-none.

Update all callers.

gtk/gtkmaplistmodel.c
gtk/inspector/controllers.c
testsuite/gtk/maplistmodel.c

index ea43269c07697fa54f9c27b920c599c107953a3b..9334f0ee4046d06c219d838de62dd781f71d1e2f 100644 (file)
@@ -412,7 +412,7 @@ gtk_map_list_model_augment (GtkRbTree *map,
 
 /**
  * gtk_map_list_model_new:
- * @model: (allow-none): The model to map or %NULL for none
+ * @model: (transfer full) (allow-none): The model to map or %NULL for none
  * @map_func: (allow-none): map function or %NULL to not map items
  * @user_data: (closure): user data passed to @map_func
  * @user_destroy: destroy notifier for @user_data
@@ -435,6 +435,9 @@ gtk_map_list_model_new (GListModel             *model,
                          "model", model,
                          NULL);
 
+  /* consume the reference */
+  g_clear_object (&model);
+
   if (map_func)
     gtk_map_list_model_set_map_func (result, map_func, user_data, user_destroy);
 
index 5c4bab15b5bd39ed2989455f020ba40a535b782a..9d1ef7ffaf6063e3cd70702cd4240f24be0766d1 100644 (file)
@@ -244,7 +244,6 @@ gtk_inspector_controllers_set_object (GtkInspectorControllers *self,
   gtk_property_lookup_list_model_set_object (self->model, object);
 
   map_model = gtk_map_list_model_new (G_LIST_MODEL (self->model), map_to_controllers, NULL, NULL);
-  g_object_unref (self->model);
 
   flatten_model = gtk_flatten_list_model_new (G_LIST_MODEL (map_model));
 
index 94a437f842ff0d4675a2ebf772cd69b5e6a37cff..b3163a61bf9e4f05863ac13e2eafb93d4934dd6d 100644 (file)
@@ -196,6 +196,8 @@ new_model (GListStore *store)
   GtkMapListModel *result;
   GString *changes;
 
+  if (store)
+    g_object_ref (store);
   result = gtk_map_list_model_new (G_LIST_MODEL (store), map_multiply, GUINT_TO_POINTER (2), NULL);
   changes = g_string_new ("");
   g_object_set_qdata_full (G_OBJECT(result), changes_quark, changes, free_changes);